﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using _1041448_DH_Utilities;

namespace _1041448_Watermarks
{
    public class Spaces : Watermark
    {
        public static bool PreprocessSource(ref string sources, string watermark, ref int maxbit, out string error){
            // Init state variables
            error = string.Empty;
            int totalSpace = 0;
            int maxInputBit = 0;
            int numCharacterInWatermark = 0;
            bool result = false;
            bool isError = false;
            string sourceTemp = sources;
            string watermarkTemp = watermark;

            // Check if sources and watermark params is null 
            if (sources == null || sources.Equals("") || watermark == null || watermark.Equals("")){
                //error = MResources.ReadResourceValue("Global.resx", "Spaces_PreprocessSource_Params_Error", out isError);
                error = "Params failed";
                return result;
            }

            sourceTemp = MString.CleanSpaceBySource(sourceTemp);

            // Count space in source
            totalSpace = MString.GetFrequenceSpaceByCharacter(sourceTemp);

            // Check if count lease than 2 
            if (totalSpace <= Constants.MINBIT){
                //error = MResources.ReadResourceValue("Global.resx", "Spaces_PreprocessSource_MinBit_Error", out isError);
                error = "Not enough space";
                return result;
            }

            // max input bit = count divide 2
            maxInputBit = totalSpace / 2;

            // Count nums character in watermark
            numCharacterInWatermark = MString.CountCharacterByString(watermarkTemp);

            // If nums more max input bit
            if (numCharacterInWatermark > maxInputBit)
            {
                //error = MResources.ReadResourceValue("Global.resx", "Spaces_PreprocessSource_BitOverfloat_Error", out isError);
                error = "Bit over float";
                return result;
            }

            // Assign maxbit var = max input bit
            maxbit = maxInputBit;
            sources = sourceTemp;
            result = true;

            // End state
            sourceTemp = string.Empty;
            watermarkTemp = string.Empty;

            return result;
        }

        public static string PreprocessWatermark(string watermark){



            return watermark;
        }

        public static bool InputWatermark(ref string sources, string watermark){
            return false;
        }

        public static string PreprocessOutputSource(string source){
            return string.Empty;
        }

        public static string GetWaterwark(string source, out bool isGetWatermark, out string messages){
            isGetWatermark = false;
            messages = string.Empty;
            return string.Empty;
        }
    }
}
